package com.circles.user.dao.sqlmap;

import java.util.HashMap;
import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.circles.group.entity.GroupDto;
import com.circles.user.dao.UserDao;
import com.circles.user.entity.UserDto;

@Repository
public class SqlMapUserDao implements UserDao {

	@Autowired
	private SqlSession sqlSession;

	@Override
	public int getCountMember() {
		return sqlSession.selectOne("UserMapper.getCountMember");
	}
	
	@Override
	public int memberRegist(HashMap<String, String> map) {
		return sqlSession.insert("UserMapper.memberRegist", map);
	}

	@Override
	public int getMemberNum(String id) {
		return sqlSession.selectOne("UserMapper.getMemberNum", id);
	}

	@Override
	public UserDto login(HashMap<String, String> map) {
		return sqlSession.selectOne("UserMapper.login", map);
	}

	@Override
	public List<GroupDto> getMyGroupList(int num) {
		return sqlSession.selectList("UserMapper.getMyGroupList", num);
	}

	@Override
	public int setProfileImage(HashMap<String, String> map) {
		return sqlSession.update("UserMapper.setProfileImage", map);
	}

	@Override
	public int insertMemberInfo(HashMap<String, String> map) {
		return sqlSession.insert("UserMapper.insertMemberInfo", map);
	}

	@Override
	public void setLast_Access(long num) {
		sqlSession.update("UserMapper.setLast_Access", num);
	}

	@Override
	public void addAccess_Count(long num) {
		sqlSession.update("UserMapper.addAccess_Count", num);
	}

	@Override
	public void deleteMember(int num) {
		sqlSession.delete("UserMapper.deleteMember", num);
	}

	@Override
	public String getProfileImage(int num) {
		return sqlSession.selectOne("UserMapper.getProfileImage", num);
	}

	@Override
	public int modifyAccounts(HashMap<String, String> map) {
		return sqlSession.update("UserMapper.modifyAccounts", map);
	}

	@Override
	public boolean fb_loginFirstUse(String id) {
		boolean check = false;
		int i = sqlSession.selectOne("UserMapper.fb_loginFirstUse", id);
		if(i==0){
			check = true;
		}
		
		return check;
	}

	@Override
	public int fb_memberRegist(HashMap<String, String> map) {
		return sqlSession.insert("UserMapper.fb_memberRegist", map);
	}

	@Override
	public UserDto fb_login(String id) {
		return sqlSession.selectOne("UserMapper.fb_login", id);
	}

	@Override
	public int fb_profileImageUpdate(HashMap<String, String> map) {
		
		int i = sqlSession.update("UserMapper.fb_profileImageUpdate", map);
		
		return i;
	}

	
}
